<?php
require_once("includes/pagetop.php");

if(isset($Alluserphone))
{
    $Alluserphone=sanitize($Alluserphone);
    
    $userinfoqry="select User_ID,Email_ID,Full_Name,Secondary_Email_ID from af_users where (Email_ID=:Email_ID or Mobile_Number=:Mobile_Number) ";
    $userinfo=$pdodbobj->fetch_array($pdodbobj->query($userinfoqry,array(":Email_ID"=>$Alluserphone,":Mobile_Number"=>$Alluserphone)));
        
    if(count($userinfo)>0)
    {
        require_once"includes/mailscript.php";
        
        $randomstring=random_string(20);
        
        $updatestring=array();
        $conditionarr=array();
        $conditionarr["User_ID"]=$userinfo[0]['User_ID'];
        $updatestring["Verify_Random_String"]=$randomstring;
        
        $emailid=$userinfo[0]['Email_ID'];
        if(isset($userinfo[0]['Secondary_Email_ID']) && trim($userinfo[0]['Secondary_Email_ID'])!='')
        {
            $emailid=$userinfo[0]['Secondary_Email_ID'];
        }
        
        $subject="Recover Password to Allyfolio Social Portal.";
        
        $message="
        <table cellspacing='2' cellpadding='2' width='100%'>
            <tr>
                <td>
                Hi ".$userinfo[0]['Full_Name'].",<br/><br></td>
            </tr>
            <tr>
                <td>
                    You have requested for changing your allyfolio account password. 
                 </td>
            </tr>
            <tr>
                <td>
                Please click on below link to reset your account password & continue with Allyfolio.<br>
                <a href='".WEBURL."resetpass.php?actcode=".$randomstring."' target='_blank'>".WEBURL."resetpass.php?actcode=".$randomstring."</a>
                </td>    
            </tr>
            <tr>
                <td>
                <br/>
                <br/>
                   Thanks,<br/>Allyfolio Support Team.
                </td>
            </tr>       
        </table>" ;  
        
        $pdodbobj->updateData("af_users",$updatestring,$conditionarr);
        if($pdodbobj->affectedrows>0)
        {
            if(sendMail($emailid,$subject,$message,$headers))
            {
                $successmsg="An email is sent to your registered Email id with reset password link. Please use that link to reset your password.";
            }
            else
            {
                $errormsg="There is an error in sending reset password email to your account.";
                
            }
        }
    }
    else
    {
        $errormsg="Please enter correct Email ID or Phone Number.";
    }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AllyFolio | Forgot Password </title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />


<script src="js/general.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js">
</script>

</head>

<body>
	<div id="main_wrapper">
    <!--=================Header Start=======================-->
	<?php
    //$pageheading="Login";
    require_once("includes/header.php");
    ?>
    <!--=================Body Contain Start=======================-->
    <div class="wrapper row2" style="margin-top:30px;">
    	<div class="header">
    		<?php
                if(isset($errormsg) && $errormsg!="")
                {
                ?>
                <div class="errormsg">
                    <?php echo $errormsg; ?>
                    <br />
                </div>
                <?php
                }
                if(isset($successmsg) && $successmsg!="")
                {
                ?>
                <div class="successmsg">
                    <?php echo $successmsg; ?>
                    <br />
                </div>
                <?php
                }
                ?>
                
                
            <div class="front-signin js-front-signin">
                <form class="signin" method="post" name="forgotpassform">
                <div class="placeholding-input username">
                
                <label class="placeholder" for="signin-email" style="text-shadow: 0px 2px 5px #666">Email or Phone No</label>
                <input class="text-input" type="text" name="Alluserphone" id="username" style="margin-left:4px;">
                </div>
                
                <div class="clearfix"></div>
                <button class="submit" type="submit" style="width:175px;" id="forgotpassbtn">Forgot Password</button>
                
                </form>
                </div>
		</div>
    </div>
    
    <div class="clearfix"></div>
    <!--=================Body Contain end=======================-->
    </div>
    <?php
    require_once("includes/footer.php");
?>
<script lang="javascript">
//<![CDATA[
    
    $("#forgotpassbtn").click(validateForgotPass);
    
    function validateForgotPass()
    {
        
        if(trim(document.getElementById('username').value)=="")
        {
            alertify.alert("Please enter either email id or phone number.");
            document.getElementById('username').focus();
            return false;
        }
        else
        {
            document.forgotpassform.submit();
        }
    }
    
//]]>

</script>